<!-- 我的计算器 -->

<template>
  <WebShow :one="obj">
    <EasyRow flex>
      <ShowNum
        v-for="[type, name] in DICT.TYPE"
        :key="type"
        :label="`${name}能耗`"
        :bind="`total${type}`"
        suffix="　kgce"
      />
      <ShowNum label="能耗总值" bind="total" suffix="　kgce" />
    </EasyRow>
  </WebShow>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'

// ============================== 导出组件 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'MyCalculator',

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [CORE.mixWeb(), CORE.mixInfo('carbon', 'carbon_')],

  /**
   * 计算属性 (慎用箭头函数)
   */
  computed: {
    /**
     * 数据对象
     */
    obj() {
      const { DICT, list, carbon_info } = this
      const obj = { total: 0, total1: 0, total2: 0, total3: 0 }

      list.forEach((row) => {
        const type = CORE.dict(DICT.TYPE, row.type, 2)
        const value = carbon_info[type] * 1000000 || 0

        Array(12).fill().forEach((_, j) => {
          const result = value * (row[`month${j + 1}`] || 0)
          obj.total += result
          obj[`total${row.type}`] += result
        })
      })

      return {
        total: +(obj.total / 1000000).toFixed(2),
        total1: +(obj.total1 / 1000000).toFixed(2),
        total2: +(obj.total2 / 1000000).toFixed(2),
        total3: +(obj.total3 / 1000000).toFixed(2),
      }
    },
  },
}
</script>
